其他
Spring Boot 新一代监控你该这么玩
▶ Spring Boot 依赖与配置
Maven 依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>io.micrometer</groupId>
<artifactId>micrometer-registry-prometheus</artifactId>
<version>1.1.4</version>
</dependency>
Actuator 配置
management.endpoints.web.exposure.include=prometheus
▶ Metrics
查看度量数据
curl http://127.0.0.1:8080/actuator/prometheus
详细说明
process_files_max_files 10240.0
tomcat_sessions_active_current_sessions 0.0
tomcat_sessions_alive_max_seconds 0.0
jvm_buffer_total_capacity_bytes{id="direct",} 81920.0
jvm_buffer_total_capacity_bytes{id="mapped",} 0.0
jvm_threads_daemon_threads 23.0
tomcat_global_request_max_seconds{name="http-nio-8080",} 10.007
tomcat_sessions_active_max_sessions 0.0
system_cpu_usage 0.2865671641791045
jvm_buffer_memory_used_bytes{id="direct",} 81920.0
jvm_buffer_memory_used_bytes{id="mapped",} 0.0
jvm_classes_loaded_classes 7910.0
jvm_memory_committed_bytes{area="heap",id="PS Survivor Space",} 1.6252928E7
jvm_memory_committed_bytes{area="heap",id="PS Old Gen",} 1.53092096E8
jvm_memory_committed_bytes{area="heap",id="PS Eden Space",} 1.77733632E8
jvm_memory_committed_bytes{area="nonheap",id="Metaspace",} 4.1680896E7
jvm_memory_committed_bytes{area="nonheap",id="Code Cache",} 9502720.0
jvm_memory_committed_bytes{area="nonheap",id="Compressed Class Space",} 5767168.0
jvm_threads_live_threads 27.0
tomcat_threads_config_max_threads{name="http-nio-8080",} 200.0
tomcat_global_received_bytes_total{name="http-nio-8080",} 270.0
tomcat_global_sent_bytes_total{name="http-nio-8080",} 97342.0
tomcat_threads_current_threads{name="http-nio-8080",} 10.0
tomcat_sessions_created_sessions_total 0.0
system_load_average_1m 5.51953125
tomcat_sessions_expired_sessions_total 0.0
jvm_buffer_count_buffers{id="direct",} 10.0
jvm_buffer_count_buffers{id="mapped",} 0.0
jvm_memory_used_bytes{area="heap",id="PS Survivor Space",} 0.0
jvm_memory_used_bytes{area="heap",id="PS Old Gen",} 2.1793344E7
jvm_memory_used_bytes{area="heap",id="PS Eden Space",} 1.62746832E8
jvm_memory_used_bytes{area="nonheap",id="Metaspace",} 3.9070768E7
jvm_memory_used_bytes{area="nonheap",id="Code Cache",} 9491136.0
jvm_memory_used_bytes{area="nonheap",id="Compressed Class Space",} 5289304.0
process_uptime_seconds 1771.052
jvm_gc_memory_allocated_bytes_total 8.3400336E7
jvm_gc_pause_seconds_count{action="end of major GC",cause="Metadata GC Threshold",} 1.0
jvm_gc_pause_seconds_sum{action="end of major GC",cause="Metadata GC Threshold",} 0.057
jvm_gc_pause_seconds_count{action="end of minor GC",cause="Metadata GC Threshold",} 1.0
jvm_gc_pause_seconds_sum{action="end of minor GC",cause="Metadata GC Threshold",} 0.014
jvm_gc_pause_seconds_max{action="end of major GC",cause="Metadata GC Threshold",} 0.0
jvm_gc_pause_seconds_max{action="end of minor GC",cause="Metadata GC Threshold",} 0.0
tomcat_sessions_rejected_sessions_total 0.0
jvm_gc_live_data_size_bytes 2.1793344E7
tomcat_threads_busy_threads{name="http-nio-8080",} 1.0
jvm_threads_peak_threads 39.0
jvm_threads_states_threads{state="runnable",} 10.0
jvm_threads_states_threads{state="blocked",} 0.0
jvm_threads_states_threads{state="waiting",} 14.0
jvm_threads_states_threads{state="timed-waiting",} 3.0
jvm_threads_states_threads{state="new",} 0.0
jvm_threads_states_threads{state="terminated",} 0.0
jvm_gc_max_data_size_bytes 2.863661056E9
http_server_requests_seconds_count{exception="None",method="GET",outcome="SUCCESS",status="200",uri="/actuator/prometheus",} 10.0
http_server_requests_seconds_sum{exception="None",method="GET",outcome="SUCCESS",status="200",uri="/actuator/prometheus",} 0.146934156
http_server_requests_seconds_max{exception="None",method="GET",outcome="SUCCESS",status="200",uri="/actuator/prometheus",} 0.0
http_server_requests_seconds_max{exception="None",method="GET",outcome="SUCCESS",status="200",uri="/api/sleep",} 0.0
jvm_gc_memory_promoted_bytes_total 1.0939928E7
logback_events_total{level="warn",} 0.0
logback_events_total{level="debug",} 0.0
logback_events_total{level="error",} 0.0
logback_events_total{level="trace",} 0.0
logback_events_total{level="info",} 17.0
process_start_time_seconds 1.556439756232E9
process_files_open_files 101.0
tomcat_global_error_total{name="http-nio-8080",} 0.0
jvm_memory_max_bytes{area="heap",id="PS Survivor Space",} 1.6252928E7
jvm_memory_max_bytes{area="heap",id="PS Old Gen",} 2.863661056E9
jvm_memory_max_bytes{area="heap",id="PS Eden Space",} 1.395130368E9
jvm_memory_max_bytes{area="nonheap",id="Metaspace",} -1.0
jvm_memory_max_bytes{area="nonheap",id="Code Cache",} 2.5165824E8
jvm_memory_max_bytes{area="nonheap",id="Compressed Class Space",} 1.073741824E9
process_cpu_usage 0.002344795186641643
jvm_classes_unloaded_classes_total 1.0
system_cpu_count 4.0
tomcat_global_request_seconds_count{name="http-nio-8080",} 15.0
tomcat_global_request_seconds_sum{name="http-nio-8080",} 14.239
Prometheus 数据结构
<metric name>{<label name>=<label value>, ...} value
Prometheus Metrics Value
Prometheus 度量值:float64,示例:1.556439756232E9 = 1556439756.232
▶ Github Demo URL
https://github.com/ChinaSilence/spring-boot-demos/tree/master/04%20-%20prometheus%20metrics
© 著作权归作者所有,转载或内容合作请联系作者
分享
● 史上最轻松入门之Spring Batch - 轻量级批处理框架实践
● APM工具寻找了一圈,发现SkyWalking才是我的真爱
● Spring Boot 注入外部配置到应用内部的静态变量
● Java 使用 UnixSocket 调用 Docker API
● Service Mesh - gRPC 本地联调远程服务